package me.zhenqu.model.dao.impl;

import me.zhenqu.model.dao.StatusDao;
import me.zhenqu.model.pojo.entity.Status;
import me.zhenqu.model.pojo.entity.StatusCount;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: yibing.tan
 * Date: 11-11-10
 * Time: 下午4:48
 * To change this template use File | Settings | File Templates.
 */
@Repository("statusDao")
public class StatusDaoImpl extends ZhenquDaoHelper<Status> implements StatusDao {

    @Override
    public Status findByID(Long id) {
        List list = getHibernateTemplate().find("from Status where status_id=?",id);
        if (list==null||list.isEmpty()) return null;
		return (Status)list.get(0);
    }

    public List<Status> findUserStatusSince(Long user_id, long since){
       return getHibernateTemplate().find("from Status where user_id=? and pubtime>? and is_comment=? order by pubtime desc",user_id, new Date(since),false);
    }

    @Override
    public List<Status> findCommentStatusSince(Status status, long since) {
        return getHibernateTemplate().find("from Status where in_reply_status_id=? and is_comment=? and pubtime>? order by pubtime desc", status.getStatus_id(),true, new Date(since));
    }
}
